﻿@page "/Adminer"
@rendermode InteractiveServer
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using HtERP.Data

<PageTitle>Admin</PageTitle>

<h3 style="color:rgb(255,0,0)">系统管理，请谨慎操作</h3>

<p>系统开发联系信箱：mmeegg@qq.com</p>
<div>
    @if (yesOrNoAdmin())
    {
        <button class="btn btn-lg btn-primary" @onclick="NewDatabase"><img src="/image/svg-white/White_journals-fill.svg" width="24" class="bi" aria-hidden="true" />创建数据库</button>
        <button class="btn btn-lg btn-primary" @onclick="初始化数据"><img src="/image/svg-white/White_key-fill.svg" width="24" class="bi" aria-hidden="true" />初始化数据表</button>

    }
    <p style="color:limegreen">@aaa</p>
</div>

@code {
    [CascadingParameter]
    private Task<AuthenticationState>? authenticationState { get; set; }
    AuthState? AuthState;


    private bool yesOrNoAdmin()
    {
        bool isAdminPro = false;
        AuthState = authenticationState?.Result as AuthState;
        if (AuthState == null)
        {
            isAdminPro = false;
            return isAdminPro;
        }
        else
        {
            isAdminPro = AuthState.IsAdminPro ?? false;
            return isAdminPro;
        }

    }

    public string? aaa = "";
    public void NewDatabase()
    {
        CreateData createData = new CreateData();
        aaa = createData.CreateDatabase();
    }
    public void 初始化数据()
    {
        CreateData createData = new CreateData();
        aaa = createData.InitializeData();
    }


}
